<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>struts2中的map遍历总结</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  <body>
  <body>
  	<s:debug></s:debug>
    <b>1.map中的value为String字符串(id属性标识迭代对象)</b><br>    
    <table border="1" width="20%" cellspacing="0" cellpadding="0">    
     <tr>    
       <td>key</td><td>value</td>
     </tr>  
     <s:iterator value="map" id="sign">
     <tr><td colspan="2"><s:property value="#sign"/></td></tr>
   	 </s:iterator>
   	 <s:iterator value="map" id="sign">  
   	 <tr>  
   		<td><s:property value="key"/><br></td>    
    	<td><s:property value="value"/></td> 
    	</tr>   
   	 </s:iterator> 
   	 <s:iterator value="map.entrySet()" id="sign"> 
   	 <tr>   
    	<td><s:property value="#sign.getKey()"/></td>   
    	<td><s:property value="#sign.getValue()"/></td>  
    	</tr>  
  	 </s:iterator>
   </table>
   
   <b>2.map中的value为Student对象</b>    
   <table border="1" width="60%" cellspacing="0" cellpadding="0">    
     <tr>    
       <td>key=value</td>    
       <td>ID</td>    
       <td>num</td>    
       <td>name</td>    
       <td>sex</td>    
       <td>age</td>    
     </tr>    
     <s:iterator value="studentMap" id="sign">    
     <tr>    
      <td><s:property value="#sign"/></td>    
      <td><s:property value="value.id"/></td>    
      <td><s:property value="value.stuNo"/></td>    
      <td><s:property value="value.name"/></td>    
      <td><s:property value="value.gender"/></td>    
      <td><s:property value="value.age"/></td>    
     </tr>    
     </s:iterator>  
     <tr><td colspan="6">使用Map.Entry可方便获取map对象key值或value值,ognl支持调用扩展方法(#sign.getValue().getId())</td></tr>
     <s:iterator value="studentMap.entrySet()" id="sign">    
     <tr>    
      <td><s:property value="#sign"/></td>    
      <td><s:property value="#sign.getValue().getId()"/></td>    
      <td><s:property value="#sign.getValue().stuNo"/></td>    
      <td><s:property value="#sign.getValue().name"/></td>    
      <td><s:property value="#sign.getValue().gender"/></td>    
      <td><s:property value="#sign.getValue().age"/></td>    
     </tr>    
     </s:iterator>  
   </table>    
   <p>    
      
      
   <b>3.map中的value为String数组</b>    
   <table border="1" width="50%" cellspacing="0" cellpadding="0">    
     <tr>    
       <td>key=value</td>    
       <td>ID</td>    
       <td>num</td>    
       <td>name</td>    
       <td>sex</td>    
       <td>age</td>    
     </tr>    
     <s:iterator value="arrayMap" id="sign">    
     <tr>    
      <td><s:property value="#sign"/></td>    
      <td><s:property value="value[0]"/></td>    
      <td><s:property value="value[1]"/></td>    
      <td><s:property value="value[2]"/></td>    
      <td><s:property value="value[3]"/></td>    
      <td><s:property value="value[4]"/></td>    
     </tr>    
     </s:iterator>    
   </table>    
   <p>    
   <b>4.map中的value为list集合</b>    
   <table border="1" width="50%"   cellspacing="0" cellpadding="0">    
     <tr>    
       <td>class</td>    
       <td>ID</td>    
       <td>stuNo</td>    
       <td>name</td>    
       <td>gender</td>    
       <td>age</td>    
     </tr>    
        
    <s:iterator value="listMap" id="sign">    
      <s:set name="total" value="#sign.value.size"/>    
      <s:iterator value="#sign.value" status="st">    
       <tr>    
         <s:if test="#st.first"><td rowspan="${total}"><s:property value="#sign.key"/></td></s:if>    
         <td><s:property value="id"/></td>    
         <td><s:property value="stuNo"/></td>    
         <td><s:property value="name"/></td>    
         <td><s:property value="gender"/></td>    
         <td><s:property value="age"/></td>    
       </tr>    
      </s:iterator>    
   </s:iterator>    
   
   <tr><td colspan="7">关于OGNL表达式的不同写法</td></tr>
     <s:iterator value="listMap.entrySet()" id="sign"> 
     <s:set name="total" value="#sign.getValue().size()"></s:set> 
     <s:iterator value="#sign.getValue()" id="ss" status="st">   
     <tr>    
      <s:if test="#st.index==0"><td rowspan="${total}"><s:property value="#sign.getKey()"/></td></s:if>    
      <td><s:property value="#ss.id"/></td>    
      <td><s:property value="#sign.getValue().get(#st.index).stuNo"/></td>    
      <td><s:property value="#sign.getValue().get(#st.index).getName()"/></td>    
      <td><s:property value="gender"/></td>    
      <td><s:property value="age"/></td>    
     </tr>  
     </s:iterator>  
     </s:iterator> 
</table>    
      
</body>    
</html>
